package io.shallwe.history;

import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
import io.shallwe.common.controller.BaseController;
import io.shallwe.common.model.Toc;

import java.util.List;

/**
 * @author : 王小伟
 * @date : 2019-07-23 16:07:33
 */
public class ParameterCurveController extends BaseController {
    @Inject
    LogTocService tocService;
    @Inject
    ParameterCurveService service;

    Toc tocDao = new Toc().dao();
    public void index(){
        render("index.html");
    }

    public void list(){
    	Integer offset = getParaToInt("offset",1);
        String barcode = get("barcode");
        String traceCode = get("traceCode");
        String rackNo = get("rackNo");
        String materialNo = get("materialNo");
        renderJson(service.paginate(offset,barcode,traceCode,rackNo,materialNo));
    }

    public void parameterCurve(){
        List<Toc> configs = tocService.listAllToc();
        set("configs",configs);
        render("parameterCurve.html");
    }

    public void curve(){
        String startTime = get("startTime");
        String endTime=get("endTime");
        String barcode = get("barcode");
        String rackNo = get("rackNo");
        String parameterName = get("parameterName");
        set("startTime",startTime);
        set("endTime",endTime);
        set("barcode",barcode);
        set("rackNo",rackNo);
        Toc config = tocDao.findFirst("select * from log_toc where remark = ?", parameterName);
        set("config",config);
        render("curve.html");
    }


    public void getData(){
        String tableName = get("tableName");
        String startTime = get("startTime");
        String endTime = get("endTime");
        if(StrKit.isBlank(tableName)){
            renderJson(Ret.fail("msg","请选择参数"));
            return;
        }
        if(StrKit.isBlank(startTime)){
            renderJson(Ret.fail("msg","请选择开始时间"));
            return;
        }
        if(StrKit.isBlank(endTime)){
            renderJson(Ret.fail("msg","请选择结束时间"));
            return;
        }
        Ret ret =service.getData(tableName,startTime,endTime);
        renderJson(ret);
    }




}
